<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>控制台 - 系统管理</title>
    <link rel="stylesheet" href="/layui/css/layui.css">
</head>
<body>
    <div class="layui-container">
        <div class="layui-row layui-col-space15">
            <div class="layui-col-md3">
                <div class="layui-card">
                    <div class="layui-card-header">用户统计</div>
                    <div class="layui-card-body" id="userCount" style="font-size: 24px; color: #1E9FFF;">
                        加载中...
                    </div>
                </div>
            </div>
            <div class="layui-col-md3">
                <div class="layui-card">
                    <div class="layui-card-header">项目统计</div>
                    <div class="layui-card-body" id="projectCount" style="font-size: 24px; color: #5FB878;">
                        加载中...
                    </div>
                </div>
            </div>
            <div class="layui-col-md3">
                <div class="layui-card">
                    <div class="layui-card-header">活跃会话</div>
                    <div class="layui-card-body" id="sessionCount" style="font-size: 24px; color: #FFB800;">
                        加载中...
                    </div>
                </div>
            </div>
            <div class="layui-col-md3">
                <div class="layui-card">
                    <div class="layui-card-header">今日登录</div>
                    <div class="layui-card-body" id="todayLogin" style="font-size: 24px; color: #FF5722;">
                        加载中...
                    </div>
                </div>
            </div>
        </div>

        <div class="layui-row" style="margin-top: 20px;">
            <div class="layui-col-md12">
                <div class="layui-card">
                    <div class="layui-card-header">快速操作</div>
                    <div class="layui-card-body">
                        <button class="layui-btn" onclick="gotoPage('user-management')">用户管理</button>
                        <button class="layui-btn layui-btn-normal" onclick="gotoPage('session-management')">会话管理</button>
                        <button class="layui-btn layui-btn-warm" onclick="gotoPage('project-management')">项目管理</button>
                        <button class="layui-btn layui-btn-danger" onclick="gotoPage('system-stats')">系统统计</button>
                    </div>
                </div>
            </div>
        </div>
    </div>

    <script src="/js/config/api.js"></script>
    <script src="/js/http.js"></script>
    <script src="/js/auth-utils.js"></script>
    <script src="/layui/layui.js"></script>
    <script src="/js/utils.js"></script>
    <script>
        layui.use(function(){
            loadDashboardData();
        });

        function loadDashboardData() {
            http.get(API_CONFIG.ADMIN.STATS)
                .then(function(res) {
                    if (res.code === 0 && res.data) {
                        document.getElementById('userCount').textContent = res.data.user_count || '0';
                        document.getElementById('projectCount').textContent = res.data.project_count || '0';
                        document.getElementById('sessionCount').textContent = res.data.active_sessions || '0';
                        document.getElementById('todayLogin').textContent = res.data.today_login || '0';
                    }
                })
                .catch(function(err) {
                    console.error('加载控制台数据失败:', err);
                });
        }

function gotoPage(page) {
    // 优先使用iframe方式（更好的体验）
    if (parent && parent.document) {
        var iframe = parent.document.getElementById('adminFrame');
        if (iframe) {
            iframe.src = '/admin/' + page;  // ✅ 最优体验
            return;
        }
    }
    
    // 降级方案：直接跳转
    // window.location.href = '/admin/' + page;  // ✅ 兼容性保障
}
    </script>
</body>
</html>